﻿using System;
using System.Windows.Forms;
using System.Net;
using System.Management;  //needs to add reference system.management to the solution,or it will be wrong.

namespace Nathan_tools
{
    public partial class _mainForm : Form
    {
        public _mainForm()
        {
            InitializeComponent();
        }

        private void btn_str_reverse_Click(object sender, EventArgs e)
        {
            Char[] str_new = tb_str1.Text.ToCharArray();
            Array.Reverse(str_new);
            tb_str1.Clear();
            foreach (char c in str_new)
            {tb_str1.Text += c.ToString(); }
        }

        private void btn_upper_Click(object sender, EventArgs e)
        {
            tb_str2.Text = tb_str2.Text.ToUpper();
        }

        private void btb_lower_Click(object sender, EventArgs e)
        {
            tb_str2.Text = tb_str2.Text.ToLower();
        }

        private void btn_split_Click(object sender, EventArgs e)
        {
            tb_split1.Clear();
            tb_split2.Clear();
            tb_split3.Clear();
            tb_split4.Clear();

            if (tb_str_tosplit.Text.Trim() != "")
            {
                string[] content = this.tb_str_tosplit.Text.Replace("\r", "").Split('\n');
                foreach (string s in content)
                {
                    try
                    {
                        string[] str_split = s.Split(tb_split_char.Text.ToCharArray());
                        tb_split1.Text += str_split[0] + "\r\n";
                        tb_split2.Text += str_split[1] + "\r\n";
                        tb_split3.Text += str_split[2] + "\r\n";
                        tb_split4.Text += str_split[3] + "\r\n";
                    }
                    catch { }
                }
            }
        }

        private void btn_form_auto_wordwrap_Click(object sender, EventArgs e)
        {
            frm_autowordwrap frmwordwrap = new frm_autowordwrap();
            frmwordwrap.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tb_mac.Clear();
            Random rd = new Random();

            if (rb_dlink .Checked ==true )   tb_mac.Text = "00:14:78:";     //dlink        
            else if (rb_giga.Checked == true) tb_mac.Text = "00:14:85:";      //giga mac    00:1d:7d
            else if (rb_intel.Checked == true) tb_mac.Text = "00:13:02:";     //intel       00:11:11
            else if (rb_dell.Checked == true) tb_mac.Text = "00:1D:09:";      //dell        00:1D:09   00:1E:4F
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);       //生成0到16之间的随机数
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);
            tb_mac.Text += ":";
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);
            tb_mac.Text += ":";
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);
            tb_mac.Text += Convert.ToString(rd.Next(0, 16), 16);
            tb_mac.Text = tb_mac.Text.ToUpper();                //转成大写
            Clipboard.SetText(tb_mac.Text);
        }

        private void btn_copytoclipboard1_Click(object sender, EventArgs e)
        {
            Clipboard.SetText (tb_split1.Text);
        }

        private void btn_copytoclipboard2_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(tb_split2.Text);
        }

        private void btn_copytoclipboard3_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(tb_split3.Text);
        }

        private void btn_copytoclipboard4_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(tb_split4.Text);
        }

        private void btn_whois_Click(object sender, EventArgs e)
        {
            frm_whois fwho = new frm_whois();
            fwho.ShowDialog();
        }

        private void btn_ip_Click(object sender, EventArgs e)
        {
            tb_host.Text =Dns.GetHostName ().ToString ();
            IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName ()); //得到主机IP
           // IpEntry .AddressList.
            tb_ip.Text = IpEntry.AddressList[0].ToString();
            tb_macc.Text = GetMacAddress();

        }
        string GetMacAddress()
        {
            try
            {
                //获取网卡硬件地址 
                string mac = "";
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        mac += mo["MacAddress"].ToString();
                        break;
                    }
                }
                moc = null;
                mc = null;
                return mac;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        } 



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btn_tobinary_Click(object sender, EventArgs e)
        {
            try
            {
                tb_numeric.Text = Convert.ToString(Convert.ToInt64(tb_numeric.Text), 2);
            }
            catch { }
        }

        private void btn_tooctal_Click(object sender, EventArgs e)
        {
            try
            {
                tb_numeric.Text = Convert.ToString(Convert.ToInt64(tb_numeric.Text), 8);
            }
            catch { }
        }

        private void btn_todecimal_Click(object sender, EventArgs e)
        {

        }

        private void btn_tohex_Click(object sender, EventArgs e)
        {
            try
            {
                tb_numeric.Text = Convert.ToString(Convert.ToInt64(tb_numeric.Text), 16);
            }
            catch { }
        }

        private void btn_sql_Click(object sender, EventArgs e)
        {
            sql_tools frm_sql = new sql_tools();
            frm_sql.ShowDialog();
        }

        private void btn_time_tools_Click(object sender, EventArgs e)
        {
            time_tools frm_time_tools = new time_tools();
            frm_time_tools.ShowDialog();
        }

        private void btn_file_rename_Click(object sender, EventArgs e)
        {
            frm_file_rename frm_filerename = new frm_file_rename();
            frm_filerename.ShowDialog();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://zyb8.cc");
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("http://zyb8.cc\nDesigned by Nathan Zhang\nQQ:5521833","zyb8.cc");
        }

        private void btn_shut_pc_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("确定要关闭电脑吗？", "重要提示！", MessageBoxButtons.YesNo))
            {
                System.Diagnostics.Process.Start("shutdown", "-s -t 0");
            }
        }

        private void btn_web_Click(object sender, EventArgs e)
        {
            frm_web fweb = new frm_web();
            fweb.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes ==MessageBox .Show ("确定要重启电脑吗？","重要提示！",MessageBoxButtons.YesNo ))
            {
                System.Diagnostics.Process.Start("shutdown", "-r");
            }
        }

        private void btn_pc_beep_Click(object sender, EventArgs e)
        {
            frm_pc_beep fpb = new frm_pc_beep();
            fpb.ShowDialog();
        }

        private void btn_link_generate_Click(object sender, EventArgs e)
        {
            frm_links_generate flg = new frm_links_generate();
            flg.ShowDialog();
        }

        private void btn_crypt_Click(object sender, EventArgs e)
        {
            frm_cryptography fc = new frm_cryptography();
            fc.ShowDialog();
        }

        private void btn_frm_pdf_Click(object sender, EventArgs e)
        {
            frm_pdf fpdf = new frm_pdf();
            fpdf.ShowDialog();
        }


   }
}

/*
 Designed by Nathan Zhang
 * http://94011.info
 QQ:5521833 
 */
